package com.in.utils;

import lombok.Data;

/**
 * @PackageName: java.entity
 * @ClassName: Result
 * @Description:
 * @Author: liulianjia
 * @Date: 2020/11/9 23:16
 */
@Data
public class Result {

    /**
     * 返回体
     */
    private Integer code;//返回状态码

    private String message;//返回消息

    private Object data;//返回数据


    /**
     * 成功，且返回体有数据
     *
     * @return
     */
    public static Result success(Integer code, String msg, Object object) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(msg);
        result.setData(object);
        return result;
    }

    /**
     * 成功，但返回体无数据
     */
    public static Result success(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }

    /**
     * @Author liulianjia
     * @Description 成功，返回体只传数据
     * @Date 2023/5/26 11:59
     **/
    public static Result success(Object object) {
        Result result = new Result();
        result.setCode(StatusCode.OK);
        result.setMessage("操作成功");
        result.setData(object);
        return result;
    }

    /**
     * 返回失败信息,返回体有数据
     */
    public static Result err(Integer code, String msg, Object object) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(msg);
        result.setData(object);
        return result;
    }

    /**
     * 返回失败信息
     */
    public static Result err(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }

    /**
     * @Author liulianjia
     * @Description 失败
     * @Date 2023/5/26 13:33
     **/
    public static Result err() {
        Result result = new Result();
        result.setCode(StatusCode.ERROR_CODE);
        result.setMessage("操作失败");
        return result;
    }
}
